package com.nuanqian.springbootdubboclient.controller;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.nuanqian.springbootdubboclient.utils.ActiveMqUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.jms.Queue;
import javax.jms.Topic;
import java.util.Date;
import java.util.Map;
import java.util.UUID;

/**
 * @author 李蒙
 * @date 2020/6/17 16:51
 */
@RestController
@RequestMapping("/mq")
public class MQTestController {

        @Autowired
//    @Qualifier("jmsMessagingTemplate")
        private JmsMessagingTemplate jmsMessagingTemplate;

        @Autowired
        private Topic topic;

        @Autowired
        private Queue queue;

        @PostMapping("/topic/test")
        public String sendTopic() {
            Map<String, Object> securityEvt = Maps.newHashMap();
            Date now = new Date();
            securityEvt.put("START_TIME", now);
            securityEvt.put("END_TIME", now);
            securityEvt.put("DVC_TYPE", "NGFW(NGTOS-v3.0)");
            securityEvt.put("SRC_ADDRESS","111.111.111.111");
            securityEvt.put("DVC_ADDRESS", "111.111.111.111");
            securityEvt.put("EVENT_TYPE","自定义类型");
            securityEvt.put("NAME", "自定义名称AA");
            securityEvt.put("UUID", UUID.randomUUID().toString().replaceAll("-", ""));
            securityEvt.put("MESSAGE", "设备登录故障");

            ActiveMqUtils.mqUtils.send(jmsMessagingTemplate,topic, Lists.newArrayList(securityEvt));
            return "success";
        }


    @PostMapping("/queue/test")
    public String sendQueue() {
        ActiveMqUtils.mqUtils.send(jmsMessagingTemplate,queue,"这是一个Queue测试"+UUID.randomUUID().toString().replace("-",""));
        return "success";
    }


}
